<?php
namespace app\admin\model;

use think\Model;

class BusShorturlHistory extends Model
{
	public function flist($res)
	{
		$cid = session('relate_id');

		if(empty($cid))
		{
			return [];
		}

		list($start, $end) = $res['seletime'];

		$list = BusShorturlHistory::alias('a')->field('a.*,bus_channel.company_name')->where('a.create_time','between time',$res['seletime'])->join('bus_channel','a.cid=bus_channel.channel_id','left')->where('cid' , $cid);

		if($res['short_url']){
			$list = $list->where('a.short_url' , 'like' , '%'.$res['short_url'].'%' );
		}

		return $list->order('a.id desc')->paginate(20)->toarray();
	}

	public function fklist($res)
	{
		$cid = session('relate_id');

		if(empty($cid))
		{
			return [];
		}

		$list = BusShorturlHistory::alias('a')
		->field('a.*,bus_channel.company_name')
		->join('bus_channel','a.cid=bus_channel.channel_id','left')
		->where('a.cid' , $cid)
		->where('a.url_code','in',$res['short_url_all']);

		if($res['short_url'])
		{
			$list = $list->where('short_url' , 'like' , '%'.$res['short_url'].'%');
		}

		return $list->order('a.id desc')->paginate(20)->toarray();
	}
}